#pragma once
#ifndef __G_ERROR_H__
#define __G_ERROR_H__

#include <string>

#include "GLog.h"
#include "GTypes.h"

namespace GUtil
{
	#define G_ERROR_MESSAGE_MAX_LEGTH	1024

	class GErrorMessage
	{
	protected:
		std::string		Message;

	public:
						GErrorMessage();
						GErrorMessage(const char* Format, ...);
		virtual			~GErrorMessage();
						
		void			SetErrorMessage(const char* Format, ...);
		const char*		GetErrorMessage() const;

		virtual void	Display() const;
	};

	class GErrorMessageWin32 : public GErrorMessage
	{
	public:
						GErrorMessageWin32();
						GErrorMessageWin32(GUInt32 ErrorCode);
						~GErrorMessageWin32();

		void			SetErrorMessage(GUInt32 ErrorCode) PLATFORM;
	};

	class GErrorMessageUNIX : public GErrorMessage
	{
	public:
						GErrorMessageUNIX();
						GErrorMessageUNIX(GUInt32 ErrorCode);
						~GErrorMessageUNIX();

		void			SetErrorMessage(GUInt32 ErrorCode) PLATFORM;
	};

	class GError
	{
	public:
		static  void	DebugBreak();

		static  void	DebugCheck(bool Condition, const char* Format, ...);

		static  void	Error(const char* Format, ...);
		static  void	Error(const GErrorMessage& Message);

		static  void	Exit(const char* Format, ...);
		static  void	Exit(const GErrorMessage& Message);
	};

}; // namespace GUtil


/*
#define	gExit( ) \
{ \
	exit( EXIT_FAILURE ); \
}

#ifdef _DEBUG
	#define	gDebugBreak( ) \
	{ \
		__debugbreak( ); \
	}
#else
	#define	gDebugBreak( ) \
	{ \
	}
#endif

#ifdef _DEBUG
	#define	GDebugCheck( Condition, ... ) \
	{ \
		if ( Condition ) \
		{ \
			gLogError( __VA_ARGS__ );	\
			_CrtDbgReport( _CRT_ASSERT, __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__ ); \
			gDebugBreak( ); \
		} \
	}
#else
	#define	GDebugCheck( Condition, ... ) \
	{ \
	}
#endif


#ifdef _DEBUG
	#define	GErrorCheck( Condition, Action, ... ) \
	{ \
		if ( Condition ) \
		{ \
			gLogError( __VA_ARGS__ );	\
			_CrtDbgReport( _CRT_ASSERT, __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__ ); \
			gDebugBreak( ); \
			Action; \
		} \
	}
#else
	#define	GErrorCheck( Condition, Action, ... ) \
	{ \
		if ( Condition ) \
		{ \
			gLogError(__VA_ARGS__);	\
			GErrorMessage::Display(__VA_ARGS__); \
			Action; \
		} \
	}
#endif

#ifdef _DEBUG
	#define	GTerminateCheck( Condition, ... ) \
	{ \
		if ( Condition ) \
		{ \
			gLogError( __VA_ARGS__ );	\
			_CrtDbgReport( _CRT_ASSERT, __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__ ); \
			gDebugBreak( ); \
			gExit( ); \
		} \
	}
#else
	#define	GTerminateCheck( Condition, ... ) \
	{ \
		if ( Condition ) \
		{ \
			gLogError( __VA_ARGS__ ); \
			GErrorMessage::Display( __VA_ARGS__ ); \
			gExit( ); \
		} \
	}
#endif
	*/
#endif